package com.example.carrierapp.util;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;

import com.example.carrierapp.config.ConstValue;
import com.example.carrierapp.ui.currency.SeePhotoActivity;
import com.example.carrierapp.ui.login.LoginActivity;
import com.example.carrierapp.ui.login.forget.ForgetActivity;
import com.example.carrierapp.ui.main.MainActivity;
import com.example.carrierapp.ui.main.dispatch.detail.DispatchSomeActivity;
import com.example.carrierapp.ui.main.dispatch.search.DispatchSearchActivity;
import com.example.carrierapp.ui.main.dispatch.waybilllist.WaybillListActivity;
import com.example.carrierapp.ui.main.find.detail.FindGoodsDetailActivity;
import com.example.carrierapp.ui.person.modifypass.ModifyPassActivity;
import com.example.carrierapp.ui.person.modifyphone.ModifyPhoneActivity;
import com.example.carrierapp.ui.person.notice.detail.NoticeDetailActivity;
import com.example.carrierapp.ui.person.video.FullscreenVideoActivity;
import com.example.carrierapp.ui.web.WebActivity;

public class ActivityUtil {



    public class AAA extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {

        }
    }

    /***
     * 跳转到Activity
     * @param context
     * @param cls
     */
    public static void startActivity(Context context, Class<?> cls) {
        Intent intent = new Intent(context, cls);
        if (!(context instanceof Activity)) {
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
        context.startActivity(intent);
    }


    /**
     * 跳转Web页
     *
     * @param context
     * @param url     跳转url
     * @param title   标题
     */
    public static void startWeb(Context context, String url, String title) {
        Intent intent = new Intent(context, WebActivity.class);
        intent.putExtra(WebActivity.EXTRA_URL, url);
        intent.putExtra(WebActivity.EXTRA_TITLE, title);
        if (!(context instanceof Activity)) {
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
        context.startActivity(intent);
    }

    /**
     * 跳转到主界面
     */
    public static void startMainActivity(Context context) {
        Intent intent = new Intent(context, MainActivity.class);
        if (!(context instanceof Activity)) {
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
        context.startActivity(intent);
    }
    public static void startMainActivity(Context context,int type) {
        Intent intent = new Intent(context, MainActivity.class);
        if (!(context instanceof Activity)) {
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
        intent.putExtra(ConstValue.TYPE, type);

        context.startActivity(intent);
    }

    /**
     * 调度详情界面
     */
    public static void startDispatchDetail(Context context, int id,boolean showOpera) {
        Intent intent = new Intent(context, DispatchSomeActivity.class);
        if (!(context instanceof Activity)) {
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
        intent.putExtra(ConstValue.ID, id);
        intent.putExtra(ConstValue.SHOW_OPERA, showOpera);
        context.startActivity(intent);
    }


    /**
     * 进入相片查看界面
     */
    public static void startSeePhoto(Context context, String path) {
        if (TextUtils.isEmpty(path)) {
            return;
        }
        Intent intent = new Intent(context, SeePhotoActivity.class);
        if (!(context instanceof Activity)) {
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
        intent.putExtra(ConstValue.FILE_PATH, path);
        context.startActivity(intent);
    }

    /**
     * 跳轉到調度搜索頁
     * @param context
     * @param type
     * @param requestCode
     */
    public static void startDispatchSearchForResult(Activity context, int type, int requestCode) {
        Intent intent = new Intent(context, DispatchSearchActivity.class);
        intent.putExtra(ConstValue.TYPE,type);
        context.startActivityForResult(intent, requestCode);
    }


    /**
     *  找货详情
     */
    public static void startFindDetail(Context context, int id,int type) {

        Intent intent = new Intent(context, FindGoodsDetailActivity.class);
        if (!(context instanceof Activity)) {
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
        intent.putExtra(ConstValue.ID, id);
        intent.putExtra(ConstValue.TYPE, type);
        context.startActivity(intent);
    }

    /**
     *  帮助视频
     */
    public static void startHelpVideo(Activity activity, String title, String urlFind) {
        Intent intent=new Intent(activity,FullscreenVideoActivity.class);
        intent.putExtra(ConstValue.URL,urlFind);
        intent.putExtra(ConstValue.TITLE,title);
        activity.startActivity(intent);
    }

    /**
     *  通知詳情
     */
    public static void startNoticeDetail(Activity activity, int id) {
        Intent intent = new Intent(activity, NoticeDetailActivity.class);
        if (!(activity instanceof Activity)) {
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
        intent.putExtra(ConstValue.ID, id);
        activity.startActivity(intent);
    }

    /**
     *  登录界面
     * @param toMain 是否去home界面
     */
    public static void startLogin(Context activity, boolean toMain) {
        Intent intent = new Intent(activity, LoginActivity.class);
        if (!(activity instanceof Activity)) {
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
        intent.putExtra(ConstValue.LOGIN_2MAIN, toMain);
        activity.startActivity(intent);
    }

    /**
     *  忘记密码界面
     * @param toMain 是否去home界面
     */
    public static void startForget(Context activity, boolean toMain) {
        Intent intent = new Intent(activity, ForgetActivity.class);
        if (!(activity instanceof Activity)) {
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
        intent.putExtra(ConstValue.LOGIN_2MAIN, toMain);
        activity.startActivity(intent);
    }

    /**
     *  運單列表
     * @param id
     * @param waybillId
     */
    public static void startWaybillList(Context activity, int waybillId, int id) {
        Intent intent = new Intent(activity, WaybillListActivity.class);
        if (!(activity instanceof Activity)) {
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
        intent.putExtra(ConstValue.ID, waybillId);
        intent.putExtra(ConstValue.TRANS_ID, id);
        activity.startActivity(intent);
    }

    public static void startModifyPass(Context context, String trim) {
        Intent intent = new Intent(context, ModifyPassActivity.class);
        if (!(context instanceof Activity)) {
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
        intent.putExtra(ConstValue.VALUE, trim);
        context.startActivity(intent);
    }
    public static void startModifyPhone(Context context, String trim) {
        Intent intent = new Intent(context, ModifyPhoneActivity.class);
        if (!(context instanceof Activity)) {
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
        intent.putExtra(ConstValue.VALUE, trim);
        context.startActivity(intent);
    }
}
